#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        vector<int> dp(nums.size() + 1);
        for (int i = 0; i < nums.size(); i++)
            dp[i + 1] = dp[i] + nums[i];

        int pos = 1;
        while (pos < dp.size())
        {
            if (dp[pos - 1] == dp[dp.size() - 1] - dp[pos])
                break;
            pos++;
        }

        return pos < dp.size() ? pos - 1 : -1;
    }
};